﻿var Common = {
    //消息提示
    ShowBox: function (status, message, title) {

        switch (status) {
            case 1:
                toastr.success(message, title);
                break;
            case 2:
                toastr.error(message, title);
                break;
            case 3:
                toastr.info(message, title);
                break;
            case 4:
                toastr.warning(message, title);
        }
    },
    ShowBoxWithFunc: function (data, title, func) {

        switch (data.Status) {
            case 1:
                toastr.success(data.Message, title)
                func(data.Data);
                break;
            case 2:
                toastr.error(data.Message, title)
                break;
            case 3:
                toastr.info(data.Message, title)
                break;
            case 4:
                toastr.warning(data.Message, title)
        }
    },
    ShowBoxWithFuncBack: function (data, title, func) {

        switch (data.Status) {
            case 1:
                toastr.success(data.Message, title)
                func(data.Id, data.Data);
                break;
            case 2:
                toastr.error(data.Message, title)
                break;
            case 3:
                toastr.info(data.Message, title)
                break;
            case 4:
                toastr.warning(data.Message, title)
        }
    },
    SingleActionWithFuncBack: function (url, title, that, func) {   //真假值修改操作

        $.post(url, $("#anti-form").serialize(), function (data) {

            switch (data.Status) {
                case 1:
                    toastr.success(data.Message, title);
                    func(that, data.Data);
                    break;
                case 2:
                    toastr.error(data.Message, title);
                    break;
                case 3:
                    toastr.info(data.Message, title);
                    break;
                case 4:
                    toastr.warning(data.Message, title);
                    break;
            }
        });
    },
    CollectionItem: function (url, title, that) {   //默认设置
        $.ajax({
            url: url,
            dataType: "json",
            type: "POST",
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({}),
            async: true,
            processData: false,
            cache: false,
            success: function (data) {
                switch (data.Status) {
                    case 2:
                        toastr.error(data.Message, title);
                        break;
                    case 1:
                        toastr.success(data.Message, title);                      
                        break;
                    case 4:
                        toastr.warning(data.Message, title)
                        break;
                }
            },
            error: function (xhr) {
                toastr.error(title + '失败！', title);
            }
        });
    },

    DeleteItem: function (url, title, that) {   //删除

        $.post(url, $("#anti-form").serialize(), function (data) {
            switch (data.Status) {
                case 1:
                    toastr.success(data.Message, title);
                    that.closest('.item-container').remove();
                    break;
                case 2:
                    toastr.error(data.Message, title);
                    break;
                case 3:
                    toastr.info(data.Message, title);
                    break;
                case 4:
                    toastr.warning(data.Message, title);
                    break;
            }
        });
    }

};

(function ($) {
    //$(".lang-select a").click(function (e) {
    //    e.preventDefault();
    //    var lang = $(this).attr("data-value");
    //    $("#culture").val(lang);
    //    $(this).parents("form").submit(); // post form
    //});


    $('.dropdown-toggle').dropdownHover();

})(jQuery);